﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DVK.SP2007.UniversalClient
{
    /// <summary>
    /// Encapsulates the ".ddoc" file XML. The SignedDoc part of the DVK container.
    /// 
    /// <remarks>
    /// This is mainly used for generating SignedDoc (.ddoc) container.
    /// </remarks>
    /// </summary>
    public class SignedDoc
    {
        DigiDocFileData[] _digiDocFileDatas;
        string signedDocString;
        /// <summary>
        /// Initializes a new instance of the <see cref="SignedDoc"/> class.
        /// </summary>
        /// <param name="digiDocFileDatas">one to many DigiDocFileData objects (file in encoded xml form).</param>
        public SignedDoc(params DigiDocFileData[] digiDocFileDatas)
        {
            _digiDocFileDatas = digiDocFileDatas;
        }

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            if (string.IsNullOrEmpty(signedDocString))
            {
                signedDocString += "<SignedDoc format=\"DIGIDOC-XML\" version=\"1.3\" xmlns=\"http://www.sk.ee/DigiDoc/v1.3.0#\">";

                foreach (var item in _digiDocFileDatas)
	            {
                    signedDocString += item.GetDataFileXml();
	            }

                signedDocString += "</SignedDoc>";
            }
            return signedDocString;
        }
    }
}
